package v1

import (
	"github.com/gin-gonic/gin"
	"guns-go/model/request"
	"guns-go/model/response"
	"guns-go/service"
)

// @Tags DictType
// @Summary 取字典类型下拉框
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysDictTypeParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysDictType/dropDown [get]
func DropDown(c *gin.Context) {

	var D request.SysDictTypeParam
	_ = c.ShouldBindQuery(&D)

	err, dictDataS := service.DropDown(&D)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}

	response.OkWithData(dictDataS, c)
}

// @Tags DictType
// @Summary 分页获取字典类型列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysDictTypeParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysDictType/page [get]
func SysDictTypePage(c *gin.Context) {

	var D request.SysDictTypeParam
	_ = c.ShouldBindQuery(&D)

	err, DictTypeResult := service.SysDictTypePage(&D, c)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(DictTypeResult, c)
}

// @Tags DictType
// @Summary 新增字典类型
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysDictTypeParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysDictType/add [post]
func SysDictTypeAdd(c *gin.Context) {

	var D request.SysDictTypeParam
	_ = c.ShouldBindJSON(&D)

	err := service.SysDictTypeAdd(&D)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}

// @Tags DictType
// @Summary 修改字典类型
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysDictTypeParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysDictType/edit [post]
func SysDictTypeEdit(c *gin.Context) {

	var D request.SysDictTypeParam
	_ = c.ShouldBindJSON(&D)

	err := service.SysDictTypeEdit(&D)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}

// @Tags DictType
// @Summary 删除字典类型
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SysDictTypeParam true "请求参数"
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysDictType/delete [post]
func SysDictTypeDelete(c *gin.Context) {

	var D request.SysDictTypeParam
	_ = c.ShouldBindJSON(&D)

	err := service.SysDictTypeDelete(&D)

	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}

// @Tags DictType
// @Summary 获取字典树
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} string "{"success":true,"data":{},"message":"请求成功","code":200}"
// @Router /sysDictType/tree [post]
func Tree(c *gin.Context) {

	err, info := service.Tree()

	if err != nil {
		response.FailWithMessage("获取字典书异常", c)
		return
	}

	response.OkWithData(info, c)
}
